
//Eli Elder
//embargo
//makefile needs this
//cardtest3: cardtest3.c dominion.o rngs.o
//	gss -o cardtest3 -g cardtest3.c dominion.o rngs.o $(CFLAGS)


#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h> 
#include <assert.h>
#include <math.h>
#include "rngs.h"

//set PRINTOUT to 0 to remove printfs out
#define PRINTOUT 1
#define ASSERTIVE 0

int checkEmbargo(int card, int choice1, int choice2, int choice3, struct gameState *afterEmbargoState, int handPos, int *bonus){
    struct gameState beforeEmbargoState;
    int returnVal;

    int player = whoseTurn(afterEmbargoState);
    //copy so we can test if the embargo we can check
    memcpy(&beforeEmbargoState, afterEmbargoState, sizeof(struct gameState));
    //do the embargo function card
    returnVal = cardEffect(embargo, choice1, choice2,choice3, afterEmbargoState, handPos, 0);

    //+2 coins
    beforeEmbargoState.coins = beforeEmbargoState.coins + 2;

    //if selected in play
    if(beforeEmbargoState.supplyCount[choice1] == -1){
	printf("that supply is out\n");
    }

    //add embargo token to supply
    beforeEmbargoState.embargoTokens[choice1]++;


    //trash card
    discardCard(handPos, player, &beforeEmbargoState, 0);

    //if the full deck counts arent the same Embargo and discard messed up
    if(fullDeckCount(player, 0, &beforeEmbargoState) < fullDeckCount(player, 0, afterEmbargoState)){
	printf("The embargo state has more cards than the test\n");
    } else if(fullDeckCount(player, 0, &beforeEmbargoState) > fullDeckCount(player, 0, afterEmbargoState)){
	printf("The embargo state has less cards than the test\n");
    }
    
#if (PRINTOUT == 1)
    //check that coins are correct just in case they chose that
    if(beforeEmbargoState.coins < afterEmbargoState->coins){
	printf("The embargo state has more coins than the test\n");
    } else if(beforeEmbargoState.coins > afterEmbargoState->coins){
	printf("The embargo state has less coins than the test\n");
    }
    
    //check that coins are correct just in case they chose that
    if(beforeEmbargoState.embargoTokens[choice1] < afterEmbargoState->embargoTokens[choice1]){
	printf("The embargo state has more embargoTokens than the test\n");
    } else if(beforeEmbargoState.embargoTokens[choice1] > afterEmbargoState->embargoTokens[choice1]){
	printf("The embargo state has less embargoTokens than the test\n");
    }
    
    //check the hand cards
    if(numHandCards(&beforeEmbargoState) < numHandCards(afterEmbargoState)){
	printf("The Embargocard has more hand cards than the test\n");
    } else if(numHandCards(&beforeEmbargoState) > numHandCards(afterEmbargoState)){
	printf("The Embargocard has less hand cards than the test\n");
    }
#endif
#if (ASSERTIVE == 1)
    //this will assert if something went wrong, those ifs above tell us what went wrong
    assert(returnVal == 0);
    //assert that the after EmbargoCard state is the same as we expect it to be with the "before" that we made like the after
    assert(memcmp(&beforeEmbargoState, afterEmbargoState, sizeof(struct gameState)) == 0);
#endif

    return 0;
}

int main(){
    int i;
    int player = 1;
    int bonus = 0;
    int numDeck = 5;
    int numDiscard = 5;
    int numHand = 5;
    int initialized;
    int coppers[MAX_DECK];
    struct gameState theGameState;
    int kingCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, salvager};


    for(i = 0; i < MAX_DECK; i++){
        coppers[i] = copper;
    }

    //setup and initialize the state                                                                                                                                              
    memset(&theGameState, 23, sizeof(struct gameState));
    initialized = initializeGame(player, kingCards, 1, &theGameState);

    //assign the deck, hand, and discard                                                                                                                                           
    theGameState.discardCount[player] = numDiscard;
    theGameState.handCount[player] = numHand;
    theGameState.deckCount[player] = numDeck;

    //mem set the deck hand and discard                                                                                                                                          
    memcpy(theGameState.discard[player], coppers, sizeof(int) * MAX_DECK);
    memcpy(theGameState.hand[player], coppers, sizeof(int) * MAX_HAND);
    memcpy(theGameState.deck[player], coppers, sizeof(int) * MAX_HAND);

    theGameState.coins = 5;
    theGameState.whoseTurn = player;
    //check steward                                                                                                                                                              
    theGameState.embargoTokens[minion] = 0;
    theGameState.supplyCount[minion] = 0;
    theGameState.playedCardCount=0;
    theGameState.hand[player][silver] = minion;
    checkEmbargo(steward, minion, silver, gold, &theGameState, silver, &bonus);
    printf("placed embargo on minion\n");

    theGameState.embargoTokens[gold] = 0;
    theGameState.supplyCount[gold] = 0;
    theGameState.playedCardCount=0;
    theGameState.hand[player][silver] = gold;
    checkEmbargo(steward, gold, silver, silver, &theGameState, silver, &bonus);
    printf("placed embargo on steward\n");

    theGameState.embargoTokens[mine] = 0;
    theGameState.supplyCount[mine] = 0;
    theGameState.playedCardCount = 0;
    theGameState.hand[player][silver] = mine;;
    checkEmbargo(steward, mine, mine, gold, &theGameState, silver, &bonus);
    printf("placed embargo on mine\n");

	printf("Note, if ASSERT and PRINTOUT are not flagged everything might look fine, but not be fine\n");
    return 0;
}
